home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
3895
/
3895.xpi
/
chrome
/
compact-ce.jar
/
content
/
compact.js
next >
Wrap
Text File
|
2009-09-18
|
31KB
|
881 lines
var CMCE = {
// services
firefox: document,
prompts: Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService),
util: null,
pref: Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService).getBranch("compact.menu."),
currentMenu: null,
toolbar: null,
menubar: null,
overlayFunction: function(oldFunc, oldCodeList, newCodeList) {
try {
var func = eval(oldFunc).toString();
for (var i = 0; i < oldCodeList.length; i++)
if (func.indexOf(oldCodeList[i]) < 0) return false;
for (var i = 0; i < oldCodeList.length; i++) func = func.replace(oldCodeList[i], newCodeList[i]);
eval(oldFunc + "=" + func);
return true;
} catch(e) { return false; }
},
getItemListFromPref: function(pref) {
return this.fromStringtoArray(nsPreferences.copyUnicharPref("compact.menu." + pref), ",");
},
fromStringtoArray: function(string, separator) {
var array = new Array();
var j = string.indexOf(separator);
for(var i=0; string; i++){
if (j == -1) {
array[i] = string;
break;
} else {
array[i] = string.substring(0, j);
string = string.substr( j+1 );
j = string.indexOf(separator);
}
}
return array;
},
modifyGoMenu: function() {
var hide = this.pref.getBoolPref("compactGoMenu");
var menu = this.firefox.getElementById("goPopup");
var modify = false;
for (var item=menu.lastChild; item; item=item.previousSibling)
try{
if (modify) item.setAttribute("cm-visibility", (hide ? "hide" : ""));
else if (item.id == "endHistorySeparator") modify = true;
} catch(e) {}
// update history max count for FX3
var place = menu.getAttribute("place");
if (place) {
var m = place.match(/place:type=(\d+)&sort=(\d+)&maxResults=/g);
if (m) {
menu.setAttribute("place", m[0]+this.pref.getIntPref("maxCount"));
var gomenu = menu.parentNode;
gomenu.parentNode.insertBefore(gomenu, gomenu.nextSibling); // apply the change, this motion is necessary
}
}
},
hideItems: function() {
var ids = this.getItemListFromPref("hidelist");
var attr = "cm-visibility";
var menubar = this.firefox.getElementById("main-menubar");
for (var item=menubar.firstChild; item; item=item.nextSibling) {
if (item.tagName != "menu") continue;
var visible = true;
for (var j=0; j<ids.length; j++) if (item.id == ids[j]) {
visible = false;
break;
}
item.setAttribute(attr, (visible ? "show" : "hide"));
}
},
hideMenuToolbar: function() {
setTimeout( function() {
var toolbar = CMCE.toolbar;
if (toolbar.tempVisible && !window.shownPopup && !toolbar.mouseOver) {
for (var menu=CMCE.menubar.firstChild; menu; menu=menu.nextSibling)
if (menu.getAttribute("_moz-menuactive")) return;
toolbar.tempVisible = false;
}
}, 0);
},
showMenuToolbar: function() {
var toolbar = CMCE.toolbar;
if ((toolbar.collapsed || toolbar.getAttribute("moz-collapsed")) && !toolbar.getAttribute("tempVisible")) toolbar.tempVisible = true;
},
setIDs: function(parent) {
for (var menu=parent.firstChild; menu; menu=menu.nextSibling)
try {
if (menu.tagName == "menu") this.setMenuItemsId(menu, parent);
} catch(e) {}
},
setMenuItemsId: function(menu, parent) {
if (!menu.id) menu.id = parent.parentNode.id + "-" + escape(menu.getAttribute("label"));
if (!menu.firstChild) return;
for (var menuitem=menu.firstChild.firstChild; menuitem; menuitem=menuitem.nextSibling)
try {
if (
menuitem.tagName == "menu" &&
(this.isPureContainer(menuitem) || menuitem.id == "viewFullZoomMenu") &&
this.isPureContainer(menuitem.firstChild)
)
this.setMenuItemsId(menuitem, menu);
else {
var label = menuitem.getAttribute("label");
if (!menuitem.id && label) menuitem.id = menu.id + "-" + escape(label);
}
} catch(e) {}
},
isPureContainer: function(item) {
if (
item &&
!item.getAttribute("onpopupshowing") &&
!item.getAttribute("onpopupshown") &&
!item.getAttribute("onpopuphiding") &&
!item.getAttribute("onpopuphidden") &&
!item.getAttribute("oncommand")
) return true;
else return false;
},
init: function() {
this.menubar = document.getElementById("main-menubar");
this.toolbar = document.getElementById("toolbar-menubar");
var isLinux = navigator.platform.indexOf("Linux") > -1;
var isFX3 = document.getElementById("placesCommands") ? true : false;
try{ this.util = Components.classes["@mozilla.org/inspector/dom-utils;1"].getService(Components.interfaces["inIDOMUtils"]); }
catch(e){}
// add ids for menu items in menu bar before doing anything about the menus.
var menubar = this.menubar;
for (var item=menubar.firstChild; item; item=item.nextSibling) if (item.id == "tinymenu" || item.id == "mergedmenu") {
this.setIDs(item.firstChild);
break;
}
this.setIDs(menubar);
// check if first run or update
var currentVersion = "4.2.0";
var lastVersion = this.pref.getCharPref("lastVersion");
if (lastVersion != currentVersion) {
this.pref.setCharPref("lastVersion", currentVersion);
// it is not first run if there is the old "firstrun" pref
try { var firstRun = this.pref.getBoolPref("firstrun") }
catch(e) { var firstRun = true }
// first-run
if (!lastVersion && firstRun) {
// save the current hidden menu status as the setting of PM
// so hidden menus will not be shown after installing PM
var hiddenMenus = "";
for (var menu=this.menubar.firstChild; menu; menu=menu.nextSibling)
if (menu.hidden && menu.tagName == "menu")
hiddenMenus = hiddenMenus + (hiddenMenus == "" ? "" : ",") + menu.id;
nsPreferences.setUnicharPref( "compact.menu.hidelist", hiddenMenus);
// alt toggle is not enabled as default as it still has bug in Linux
if (isLinux) this.pref.setBoolPref("altToggle", false);
setTimeout( function(This) {
This.prompts.alert(null, "Personal Menu", document.getElementById("compact-firstrun").label);
// pop a confirm for asking whether add the buttons
if (This.prompts.confirm(null, "Personal Menu", document.getElementById("compact-addbutton").label)) {
var toolbar = document.getElementById("nav-bar");
if (toolbar.collapsed) toolbar = This.toolbar;
for (var i = 0; i < 3; i++)
toolbar.insertItem(["compact-bk-menu2", "compact-go-menu2", "compact-menu-button"][i]);
toolbar.setAttribute("currentset", toolbar.currentSet);
document.persist(toolbar.id,"currentset");
BrowserCustomizeToolbar();
}
}, 750, this);
} else {
// clear old prefs
var prefs = [
"advModeB", "advModeH", "error", "HMC", // since 3.0
"defaultitemlist", "delay", "firstrun", "hidemenu", "hidemenubar", "oldStyle", // since 4.0
"bookmarkMiddleClickOpens", "bookmarkRightClickOpens", // since 4.1pre
"menuPosition-menu", "menuPosition-bookmarks", "menuPosition-history", // since 4.1
"warning" // since 4.2.0
];
for (var i=0; i<prefs.length; i++) try { this.pref.clearUserPref(prefs[i]) } catch(e) {}
}
}
this.hideItems();
this.modifyGoMenu();
// something causes "Bookmarks Toolbar" not working in FX 3.0
try {
initBookmarksToolbar();
} catch(e) {}
this.advMode();
this.updateIcon();
// modify functions
// modify for histroy max count
this.overlayFunction(
"updateGoMenu",
[
"if (count > 10",
"count = 10;"
],
[
'var maxCount = CMCE.pref.getIntPref("maxCount"); if (count > maxCount',
"count = maxCount;"
]
);
setTimeout(function(This) {
// modify for bookmarks menu middle clicking for fx 2 or below
This.overlayFunction(
"BookmarksMenu.loadBookmarkMiddleClick",
[
"BookmarksMenuDNDObserver.onDragCloseTarget",
"BookmarksMenuDNDObserver.mCurrentDragOverTarget = null",
"this.loadBookmark(aEvent, aEvent.target, aDS);"
],
[
'if (cmHideMenu) BookmarksMenuDNDObserver.onDragCloseTarget',
'var cmHideMenu = CMCE.pref.getBoolPref("hidepopup"); if (cmHideMenu) BookmarksMenuDNDObserver.mCurrentDragOverTarget = null',
'if (aEvent.target.localName != "menu" && !cmHideMenu && gBrowser.currentURI.spec == "about:blank" && !gBrowser.mIsBusy) CMCE.openUrl(aEvent); else this.loadBookmark(aEvent, aEvent.target, aDS);'
]
);
// for fx 3
This.overlayFunction(
"BookmarksEventHandler.onClick",
[
'if (target.localName == "menu"',
"this.onCommand(aEvent);"
],
[
'var cmHideMenu = CMCE.pref.getBoolPref("hidepopup"); if (cmHideMenu) if (target.localName == "menu"',
'if (aEvent.target.localName != "menu" && !cmHideMenu && gBrowser.currentURI.spec == "about:blank" && !gBrowser.mIsBusy) CMCE.openUrl(aEvent, true); else this.onCommand(aEvent);'
]
);
}, 0, this);
// modify for toggle menu toolbar
this.overlayFunction(
"onViewToolbarsPopupShowing",
[
'type != "menubar"',
'document.createElement("menuitem");'
],
[
"true",
'document.createElement("menuitem"); if (toolbar.id == "toolbar-menubar") menuItem.addEventListener("command", function() { CMCE.toolbar._collapsed = !CMCE.toolbar._collapsed; if (CMCE.toolbar._collapsed) setTimeout(CMCE.prompts.alert, 0, null, "Personal Menu", document.getElementById("compact-warning").label); }, false); else{}'
]
);
// workaround with Menu Editor
this.overlayFunction(
"MenuEdit.editMenu",
["if (!MenuEditRDF.getVisibility(node)"],
['if (!MenuEditRDF.getVisibility(node) && p.id=="contentAreaContextMenu"']
);
var toolbar = this.toolbar;
// handle menus toolbar toolgling
toolbar.setAttribute("hideBorderTop", this.pref.getBoolPref("hideBorderTop"));
toolbar.__defineGetter__("_collapsed", function(){
return this.getAttribute("_collapsed") == "true";
});
toolbar.__defineSetter__("_collapsed", function(){
this.setAttribute("_collapsed", arguments[0]);
setTimeout(function(This, collapsed){
This.isToogling = true;
This.removeAttribute("collapsed");
document.persist(This.id, "collapsed");
This.collapsed = collapsed;
This.isToogling = false;
}, 0, this, arguments[0]);
CMCE.pref.setBoolPref("toolbarCollapsed", arguments[0]);
});
toolbar._collapsed = this.pref.getBoolPref("toolbarCollapsed");
toolbar.addEventListener("DOMAttrModified", function(event){
if (event.attrName == "collapsed" && event.target == this) {
if (!this.isToogling && this.collapsed != this._collapsed) this.collapsed = this._collapsed;
}
}, true);
// add alt-toggle feature
toolbar.__defineGetter__("altToggle", function(){
return this.getAttribute("altToggle") == "true";
});
toolbar.__defineSetter__("altToggle", function(){
this.setAttribute("altToggle", arguments[0]);
});
toolbar.altToggle = this.pref.getBoolPref("altToggle");
toolbar.__defineGetter__("tempVisible", function(){
return this.getAttribute("tempVisible") == "true";
});
toolbar.__defineSetter__("tempVisible", function(){
this.setAttribute("tempVisible", arguments[0]);
if (!arguments[0])
setTimeout(function(This) {
This.removeAttribute("tempVisible");
}, 250, this);
});
setTimeout( function(toolbar) {
toolbar.addEventListener("DOMMenuBarInactive", function(event) {
if (this.altToggle) CMCE.hideMenuToolbar();
}, false);
toolbar.addEventListener("DOMMenuBarActive", function(event){
if (this.altToggle) CMCE.showMenuToolbar();
}, false);
toolbar.addEventListener("mouseover", function(){
this.mouseOver = true;
}, true);
toolbar.addEventListener("mouseout", function(event){
this.mouseOver = false;
if (this.altToggle) CMCE.hideMenuToolbar();
}, true);
}, 100, toolbar);
if (isLinux) {
// in linux, menubar cannot be active after pressing alt key only, so we sould check the alt key pressing
window.addEventListener("keydown", function(event) {
this.altKey = event.keyCode == 18 && !event.ctrlKey && !event.shiftKey && !event.metaKey;
}, true);
window.addEventListener("keyup", function(event) {
if (this.altKey && CMCE.toolbar.altToggle)
if (CMCE.toolbar.tempVisible) CMCE.hideMenuToolbar();
else setTimeout(CMCE.showMenuToolbar, 0);
this.altKey = false;
}, true);
// firefox cannot aware the release of alt key when main window is inactive
window.addEventListener("blur", function() {
this.altKey = false;
}, true);
} else {
// prevent the PM buttons being active after pressing alt key only
window.addEventListener("keydown", function(event) {
if (event.keyCode == 18 && !event.ctrlKey && !event.shiftKey && !event.metaKey) {
var cm_buttons = document.getElementsByAttribute("class", "cm-button");
if (cm_buttons[0] && cm_buttons[0].getAttribute("classicMenu") == "true") return;
for (var i=0; i<cm_buttons.length; i++) {
cm_buttons[i].firstChild.firstChild.firstChild.hidePopup();
cm_buttons[i].firstChild.hidden = true;
}
setTimeout(function(cm_buttons) {
for (var i=0; i<cm_buttons.length; i++) cm_buttons[i].firstChild.hidden = false;
}, 0, cm_buttons);
}
}, true);
}
window.addEventListener("popupshown", function(event) {
// event.target is main-window when tooltiptext shows
if (event.target.id != "main-window" && !this.shownPopup && event.target.tagName != "tooltip")
this.shownPopup = event.target;
}, true);
window.addEventListener("popuphidden", function(event) {
if (event.target == this.shownPopup) {
this.shownPopup = null;
if (CMCE.toolbar.tempVisible) CMCE.hideMenuToolbar();
// prevent showing menus toolbar after closeing menupopup by alt key
var toolbar = CMCE.toolbar;
if (toolbar.altToggle && !toolbar.tempVisible) toolbar.tempVisible = false;
}
}, true);
// add auto-switch menu feature
setTimeout( function(toolbar) {
toolbar.addEventListener("popupshowing", function(event) {
if (CMCE.pref.getBoolPref("popupmenu")) if(event.target.parentNode.parentNode.id == "main-menubar")
CMCE.currentMenu = event.target;
}, true);
toolbar.addEventListener("popuphidden", function(event) {
if(event.target.parentNode.parentNode.id == "main-menubar") CMCE.currentMenu = null;
}, true);
toolbar.addEventListener("mouseover", function(event) {
var item = event.target;
var currentMenu = CMCE.currentMenu;
if (currentMenu && item.tagName == "menu" &&
currentMenu.parentNode.parentNode.id != "main-menubar" &&
item.parentNode.id == "main-menubar") {
currentMenu.parentNode.removeAttribute("_moz-menuactive");
currentMenu.hidePopup();
item.setAttribute("_moz-menuactive", true);
setTimeout(function(item){item.showPopup()}, 0, item.firstChild);
}
}, true);
}, 100, toolbar);
// add customized toolbar context menu feature
var context = document.getElementById("toolbar-context-menu");
context.addEventListener("popupshowing", function(event) {
CMCE.onOpenMenu(this, event, this.cm_list);
}, true);
context.addEventListener("popuphidden", function(event) {
CMCE.onCloseMenu(this, event);
}, true);
context.cm_start = context.appendChild(document.createElement("menuseparator"));
context.cm_start.id = "cm-contextItem-start";
context.setAttribute("cmpopup", true);
context.addEventListener("DOMMenuItemActive", CMCE.showSTXT, false);
context.addEventListener("DOMMenuItemInactive", CMCE.restoreSTXT, false);
},
setAdv: function(target, type) {
var i = this.firefox.getElementsByAttribute("containerOf", type)[0];
if (!i) return;
target.firstChild.original_position = target.firstChild.position;
var point = this.firefox.createElement("separator");
point.id = "cmce-adv-restorePoint-"+target.id;
point.advRestorePoint = true;
point.hidden = true;
point.oriId = target.id;
target.parentNode.replaceChild(point, target);
i.appendChild(target);
i.nextSibling.label = target.getAttribute("label");
target.isButton = true;
},
advMode: function() {
// check if there is the menu
var target = this.firefox.getElementById(
["bookmarksMenu", "yb_menu", "pof-menu", "ScrapBookMenu"][this.pref.getIntPref("BookmarksButton-menu")]);
// if not, use bookmarks menu
if (!target) target = this.firefox.getElementById("bookmarksMenu");
this.setAdv(target ? target : this.firefox.getElementById("bookmarks-menu"), "bookmarks");
this.setAdv(this.firefox.getElementById("goPopup").parentNode, "history");
},
stopPropagation: function(event) {
event.stopPropagation();
},
closeAllPopup: function(item) {
var menu = item.parentNode;
while (menu.parentNode.parentNode.tagName == "menupopup" || menu.parentNode.parentNode.tagName == "popup")
menu = menu.parentNode.parentNode;
menu.hidePopup();
},
middleClickHandler: function(event) {
if (event.button == 1) {
//a special fix for undo closed tab menu
if (event.currentTarget.id == "historyUndoMenu")
HistoryMenu.populateUndoSubmenu();
setTimeout( function(menu) {
if (menu.getAttribute("open") == menu.getAttribute("disabled")) CMCE.closeAllPopup(menu);
}, 0, event.currentTarget);
}
},
updateMenuList: function() {
for (var i = 0; i < 2; i++) {
var pop = this.firefox.getElementById(["menubutton-popup", "toolbar-context-menu"][i]);
if (pop) pop.cm_list = nsPreferences.copyUnicharPref("compact.menu." + ["itemlist", "showlist"][i]);
//this.initializeMenu(pop, this.fromStringtoArray(pop.cm_list, ","));
}
},
onOpenMenu: function(menu, event, list) {
if (event.target != menu) return;
if (!menu.cm_initialized) {
if (document.getElementById("cmd_CustomizeToolbars").getAttribute("disabled")) return;
this.initializeMenu(menu, this.fromStringtoArray(list, ","));
}
this.createMenu(menu, true, menu.id);
},
initializeMenu: function(menu, itemsId) {
var topMenu = menu;
var initializingToolbar = false;
var toolbarPalette = document.getElementById("navigator-toolbox").palette;
var editMenuItem = document.getElementById(
menu.id == "toolbar-context-menu" ? "compact-showhide-prefs" : "compact-extra-prefs");
for (var i = 0; i < itemsId.length; i++) {
if (itemsId[i] == "----")
menu.insertBefore(document.createElement((menu.tagName=="toolbar" ? "toolbar" : "menu") + "separator"), menu.cm_end);
else if (itemsId[i] == "cm-submenu") {
menu = menu.insertBefore(document.getElementById(itemsId[i]).cloneNode(true), menu.cm_end);
menu.setAttribute("label", itemsId[++i]);
if (itemsId[++i] != "empty") menu.setAttribute("accesskey", itemsId[i]);
menu = menu.firstChild;
}
else if (itemsId[i] == "cm-submenu-end" || itemsId[i] == "cm-buttons-box-end") {
if (!menu.hasChildNodes()) menu.appendChild(editMenuItem.cloneNode(true));
menu = menu.parentNode.parentNode;
initializingToolbar = false;
}
else if (itemsId[i] == "cm-toolbar-spring")
menu.appendChild(document.createElement("toolbarspring")).setAttribute("flex", 1);
else if (itemsId[i] == "cm-toolbar-spacer")
menu.appendChild(document.createElement("toolbarspacer"));
else if (initializingToolbar) {
// var item = document.getElementById(itemsId[i]);
// if (item && item.parentNode.localName == "toolbar") continue;
for (var item = toolbarPalette.firstChild; item && item.id != itemsId[i]; item = item.nextSibling);
if (item) {
menu.appendChild(item.cloneNode(true));
switch(item.id) {
case "ietab-button":
IeTab.prototype.updateToolButton();
break;
}
}
}
else if (itemsId[i] == "cm-buttons-box") {
menu = menu.insertBefore(document.getElementById(itemsId[i]).cloneNode(true), menu.cm_end).firstChild;
menu.cm_menu_position = topMenu.position;
for (var j=0; j<3; j++) menu.setAttribute(["adv", "iconsize", "mode"][j], itemsId[++i]);
initializingToolbar = true;
}
else {
var item = document.getElementById(itemsId[i]);
if (!item) continue;
var dummy = item.cloneNode(false);
dummy.disabled = true;
dummy.id = "cmRestorePoint-" + itemsId[i];
dummy.target = item;
// these menuitems need to be updated their status when their original menu shows
var identity = item.command ? item.command : item.id;
var update_cmd;
switch (identity) {
case "historyUndoMenu":
update_cmd = "HistoryMenu.populateUndoSubmenu();";
break;
case "historyUndoWindowMenu":
update_cmd = "HistoryMenu.populateUndoWindowSubmenu();";
break;
case "Browser:SaveFrame":
update_cmd = "getContentAreaFrameCount();";
break;
case "cmd_fullZoomToggle":
update_cmd = "FullZoom.updateMenu();";
break;
case "checkForUpdates":
update_cmd = "buildHelpMenu();";
break;
case "ietab-toolsmenu":
update_cmd = "IeTab.prototype.updateToolsMenuItem({originalTarget: document.getElementById('menu_ToolsPopup')});";
break;
case "cmd_undo": case "cmd_redo": case "cmd_cut": case "cmd_copy": case "cmd_paste":
case "cmd_selectAll": case "cmd_delete": case "cmd_switchTextDirection":
update_cmd = "goUpdateCommand('" + identity + "');";
break;
default:
update_cmd = "";
}
dummy.update_cmd = update_cmd;
menu.insertBefore(dummy, menu.cm_end);
item.cm_restorePoint = dummy;
}
}
if (!menu.hasChildNodes()) menu.appendChild(editMenuItem.cloneNode(true));
menu.cm_initialized = true;
},
createMenu: function(menu, isTopMenu, topMenuId) {
for (var i = 0; i < menu.childNodes.length; i++) {
var item = menu.childNodes[i];
if (item.id == "cm-submenu") {
this.createMenu(item.firstChild, false, topMenuId);
continue;
}
var target = item.target
if (!target) continue;
if (item.update_cmd)
try {
eval(item.update_cmd);
} catch(e) {}
var itemPosition = item.nextSibling;
target.parentNode.replaceChild(item, target);
menu.insertBefore(target, itemPosition);
if (isTopMenu) {
target.addEventListener("popupshowing", CMCE.stopPropagation, false);
target.addEventListener("popuphidden", CMCE.stopPropagation, false);
if (target.tagName == "menu") target.addEventListener("click", CMCE.middleClickHandler, false);
}
}
},
onCloseMenu: function(menu, event) {
if (event.target != menu) return;
setTimeout(this.restoreMenu, 0, menu, true);
},
restoreMenu: function(menu, isTopMenu) {
var restore = !menu.cm_start;
for (var i = 0; i < menu.childNodes.length; i++) {
var item = menu.childNodes[i];
if (item == menu.cm_end) break;
if (restore) CMCE.restoreItem(item, menu, isTopMenu);
else if (menu.cm_start == item) restore = true;
}
},
restoreItem:function(item, menu, inTopMenu) {
if (item.id == "cm-submenu") CMCE.restoreMenu(item.firstChild, false);
else if (item.cm_restorePoint) {
var position = item.nextSibling;
item.cm_restorePoint.parentNode.replaceChild(item, item.cm_restorePoint);
menu.insertBefore(item.cm_restorePoint, position);
if (inTopMenu) {
item.removeEventListener("popupshowing", CMCE.stopPropagation, false);
item.removeEventListener("popuphidden", CMCE.stopPropagation, false);
item.removeEventListener("click", CMCE.middleClickHandler, false);
}
}
},
bkclick: function(button, event) {
if (event.target != button || event.button == 0) return;
try { switch(this.pref.getIntPref("bookmarks" + (event.button == 1 ? "Middle" : "Right") + "ClickOpens")) {
case 1:
try {
PlacesCommandHook.bookmarkCurrentPage(true, PlacesUtils.bookmarksMenuFolderId);
} catch(e) {
addBookmarkAs(document.getElementById("content"), false);
}
break;
case 2: toggleSidebar("viewBookmarksSidebar"); break;
case 3: toOpenWindowByType("bookmarks:manager","chrome://browser/content/bookmarks/bookmarksManager.xul"); break;
case 4:
try {
gBookmarkAllTabsHandler.doCommand();
} catch(e) {
addBookmarkAs(document.getElementById("content"), true);
}
break;
case 5: toggleSidebar("viewYBookmarksSidebar"); break;
case 6: yAddBookMark.open(); break;
case 7: gPofUI.openAddToFavoritesDialog(); break;
case 8: gPofUI.openOrganizeFavoritesDialog(); break;
case 9: sbBrowserOverlay.execCapture(0, null, false, "urn:scrapbook:root"); break;
case 10: sbBrowserOverlay.execCapture(0, null, true , "urn:scrapbook:root"); break;
case 11: sbMenuHandler.execCaptureAllTabs(); break;
case 12: toggleSidebar("viewScrapBookSidebar"); break;
case 13: sbCommonUtils.openManageWindow(); break;
case 14: PlacesCommandHook.showPlacesOrganizer("AllBookmarks"); break;
case 15: sbBrowserOverlay.execBookmark('ScrapBookContextPicking');
}} catch(e) {
// show toolbar context when it gets an error.
// // when we right-click the content and the context showed,
// // toolbar context doesn't show in a correct position, so we don't use this fixing yet
// if (event.button==2)
// document.getElementById("toolbar-context-menu").showPopup(event.currentTarget, event.clientX+2, event.clientY+2, "context");
}
},
goclick: function(button, event) {
if (event.target != button || event.button == 0) return;
try { switch(this.pref.getIntPref("history" + (event.button == 1 ? "Middle" : "Right") + "ClickOpens")) {
case 1: toggleSidebar("viewHistorySidebar"); break;
case 2:
try {
gBrowser.undoRemoveTab();
} catch(e) {
undoCloseTab();
}
break;
case 3: openMe("window"); break;
case 5: openMe("sidebar"); break;
case 6: PlacesCommandHook.showPlacesOrganizer("History");
}} catch(e) {
}
},
menuclick: function(button, event) {
if (event.target == button && this.pref.getIntPref("menuMiddleClickOpens") > 0 && event.button == 1)
window.openDialog(
"chrome://compact-ce/content/compactPrefDialog.xul",
"Personal Menu",
"chrome,centerscreen,dependent,minimizable,resizable",
"menubutton-tree");
},
showAll: function() {
this.toolbar._collapsed = false;
this.toolbar.tempVisible = false;
nsPreferences.setUnicharPref( "compact.menu.hidelist", "");
this.hideItems();
},
openUrl: function(event, isFX3BK) {
openUILinkIn(
isFX3BK ? event.originalTarget.node.uri : event.target.statusText,
gBrowser.currentURI.spec == "about:blank" && !gBrowser.mIsBusy ? "current" : "tab"
);
},
buttonPopShowHide: function(pop, event) {
if (event.target != pop) return;
var showing = event.type == "popupshowing";
if (this.pref.getBoolPref("popupmenu")) this.currentMenu = showing ? pop : null;
pop.parentNode.parentNode.nextSibling.setAttribute("open", showing); // in fx3beta , "button.open" method doesn't work
},
mouseover: function(el, event) {
var menu = el.firstChild;
// setPseudo
this.pseudoHandle(el, event, true);
// popup menu
if (this.currentMenu && this.currentMenu != menu.firstChild) {
this.currentMenu.parentNode.removeAttribute("_moz-menuactive");
this.currentMenu.hidePopup();
setTimeout(function(M){
M.firstChild.showPopup();
M.setAttribute("_moz-menuactive", true);
}, 0, menu);
}
// update tooltip
if (event.target == menu && el.parentNode.getAttribute("classicMenu") != "true") {
menu.tooltipText = el.getAttribute("Tip");
if (this.pref.getBoolPref("enableHotkey")) {
var accesskey = menu.getAttribute("accesskey");
if (accesskey) menu.tooltipText += " (Alt+" + accesskey.toUpperCase() + ")";
}
}
},
addButtonEventListener: function(menubar, type) {
var menu = menubar.firstChild;
if (menu && !menu.eventAdded) {
if (type == "go") menu.addEventListener("click", function(event) {
if(this.isButton) CMCE.goclick(this, event);
}, false);
else menu.addEventListener("click", function(event) {
if(this.isButton) CMCE.bkclick(this, event);
}, false);
menu.firstChild.addEventListener("popupshowing", function(event) {
if(this.parentNode.isButton) CMCE.buttonPopShowHide(this, event);
}, false);
menu.firstChild.addEventListener("popuphidden", function(event) {
if(this.parentNode.isButton) CMCE.buttonPopShowHide(this, event);
}, false);
menu.eventAdded = true;
}
},
showSTXT:function(event) {
var url = event.target.statusText;
if (url) {
var status = document.getElementById("statusbar-display");
CMCE.menubar._originalStatusText = status.label;
status.label = url;
}
},
restoreSTXT: function(event) {
if (event.target.statusText)
document.getElementById("statusbar-display").label = CMCE.menubar._originalStatusText;
},
updateIcon: function() {
// set the appearance of buttons
var notFX1_5 = this.firefox.getElementById("Tools:Addons");
var isFX3 = this.firefox.getElementById("placesCommands");
var positions = ["before_end", "after_end", "before_start", "after_start"];
var enable_hotkey = this.pref.getBoolPref("enableHotkey");
var noarrow = this.pref.getBoolPref("noarrow");
var classic_menu = !this.pref.getBoolPref("buttonStyle");
var buttons = this.firefox.getElementsByAttribute("class", "cm-button");
for (var i=0; i<buttons.length; i++) {
var button = buttons[i].lastChild;
var type = buttons[i].firstChild.getAttribute("containerOf");
button.setAttribute("noarrow", noarrow);
var menu = button.previousSibling.firstChild;
menu.firstChild.position = positions[this.pref.getIntPref("position-" + type)];
if (!enable_hotkey) {
menu.original_accessKey = menu.getAttribute("accesskey");
menu.removeAttribute("accesskey");
} else if (menu.original_accessKey)
menu.setAttribute("accesskey", menu.original_accessKey);
button.parentNode.setAttribute("classicMenu", classic_menu);
if (!classic_menu) menu.setAttribute("flex", 1);
else menu.removeAttribute("flex");
menu.parentNode.appendChild(menu); // update the flex status
button.hidden = classic_menu;
if (notFX1_5) button.setAttribute("cmFirefox2", true);
if (noarrow || !notFX1_5) button.setAttribute("orient", "vertical");
else button.setAttribute("orient", "horizontal");
// in FX3, this attribute makes the statustexts of bookmark and history items cannot be shown
if (!isFX3) button.previousSibling.setAttribute("statusbar", "statusbar-display");
button.parentNode.appendChild(button); // update the orient and mousethrough status
if (type != "menu") {
button.parentNode.setAttribute("context",
this.pref.getIntPref(type+"RightClickOpens") > 0 ? "" : "toolbar-context-menu");
} else button.previousSibling.hidden = false;
}
this.updateMenuList();
},
pseudoHandle: function(el, event, hover) {
el = el.nextSibling;
if (el.hidden) return;
this.setPseudo(el, event, hover);
},
setPseudo: function(el, event, hover) {
try {
if (event.button != 0) return;
this.util.setContentState(el, 4);
//since onmousedown is fired before onpopupshown, which is the moment that "open" is set, so need some delay
setTimeout( function(util, el, hover) {
if(el.getAttribute("open") == "true") util.setContentState((hover ? el.ownerDocument.documentElement : el), 1);
}, 1, this.util, el, hover);
} catch(e) {}
}
}